<template>
    <div>
        <div :class="{loginBox:flag,beforshow:!flag}">
            <div id="loginBoxTop">
                <span class="iconfont icon-ren logo"></span>
                <span>未登录</span>
            </div>
            <div id="loginWay">账号密码登录</div>
            <input type="text" placeholder="请输入邮箱" v-model="email">
            <input type="password" placeholder="请输入密码" v-model="pwd">
            <!-- <span class="forget">忘记密码</span> -->
            <div>使用网站账号登录</div>
            <div>
                <a href="#"><img src="../imges/zhi.png" alt=""></a>
                <a href="#"><img src="../imges/wei.png" alt=""></a>
            </div>
        </div>
        <div id="loginBoxFoot" v-if="flag">
                <span id="registered" @click="changeComponents">立刻注册</span>
                <span id="login" @click="login">登录</span>
            </div> 
            <span id="error" v-show="error">账号不存在或密码错误</span>
    </div>
  

</template>
<script>
export default {
  data() {
    return {
      email: "", //邮箱
      pwd: "", //密码
      error: false,
      flag: false,
    };
  },

  async login() {
    let sign = await this.axios.post("/lqc/login", {
      email: this.email,
      pwd: this.pwd,
    });
    if (sign.data) {
      window.localStorage.setItem("isLogin", true);
      window.localStorage.setItem("email", this.email);
      this.$store.commit("changeLoginName", "user");
      window.location.reload();
    } else {
      this.error = "true";
      setTimeout(() => {
        this.error = "false";
      }, 1000);
    }
  },

  methods: {
    changeComponents() {
      this.$store.commit("changeLoginName", "registered");
    },
    async login() {
      let sign = await this.axios.post("/lqc/login", {
        email: this.email,
        pwd: this.pwd,
      });
      if (sign.data) {
        window.localStorage.setItem("isLogin", true);
        window.localStorage.setItem("email", this.email);
        this.$store.commit("changeLoginName", "user");
        window.location.reload();
      } else {
        this.error = "true";
        setTimeout(() => {
          this.error = "false";
        }, 1000);
      }
    },
  },
  mounted() {
    setTimeout(() => {
      this.flag = true;
    }, 100);
  },
};
</script>
<style lang="scss" scpoed>
.beforshow {
  overflow: hidden;
  transition: all 0.4s;
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  background-color: #fff;
  padding: 0 30px;
  box-sizing: border-box;
}
.loginBox {
  overflow: hidden;
  transition: all 1s;
  position: absolute;
  top: 0;
  right: 0;
  width: 380px;
  height: 420px;
  background-color: #fff;
  padding: 0 30px;
  box-sizing: border-box;
  input {
    display: block;
    width: 100%;
    height: 40px;
    border: none;
    outline: none;
    border-bottom: 1px solid rgb(232, 232, 232);
    margin-top: 20px;
  }
  div {
    text-align: center;
    margin-top: 30px;
    a {
      margin-left: 10px;
    }
  }
}
#loginBoxTop {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
}
.logo {
  font-size: 25px;
}
#loginWay {
  text-align: center;
  margin-top: 20px;
  font-size: 20px;
  font-weight: 800;
}
.forget {
  font-size: 12px;
  font-weight: 600;
  margin-left: 250px;
  margin-top: 20px;
}
#loginBoxFoot {
  position: absolute;
  top: 420px;
  right: 0;
  display: flex;
  width: 380px;
  span {
    flex: 1;
    text-align: center;
    height: 70px;
    line-height: 70px;
    font-size: 14px;
    cursor: pointer;
  }
}
#registered {
  color: #fff;
  background-color: rgb(51, 51, 51);
}
#login {
  color: black;
  background-color: rgb(255, 227, 42);
  font-weight: 600;
}
#error {
  position: fixed;
  height: 40px;
  border: none;
  outline: none;
  border-bottom: 1px solid rgb(232, 232, 232);
  margin-top: 20px;
}
div {
  text-align: center;
  margin-top: 30px;
  a {
    margin-left: 10px;
  }
}
#loginBoxTop {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
}
.logo {
  font-size: 25px;
}
#loginWay {
  text-align: center;
  margin-top: 20px;
  font-size: 20px;
  font-weight: 800;
}
.forget {
  font-size: 12px;
  font-weight: 600;
  margin-left: 250px;
  margin-top: 20px;
}
#loginBoxFoot {
  position: absolute;
  top: 420px;
  right: 0;
  display: flex;
  width: 380px;
  span {
    flex: 1;
    text-align: center;
    height: 70px;
    line-height: 70px;
    font-size: 14px;
    cursor: pointer;
  }
}
#registered {
  color: #fff;
  background-color: rgb(51, 51, 51);
}
#login {
  color: black;
  background-color: rgb(255, 227, 42);
  font-weight: 600;
}
#error {
  position: fixed;
  height: 40px;
  width: 200px;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  background-color: rgb(0, 0, 0, 0.7);
  text-align: center;
  line-height: 40px;
  color: white;
  display: none;
}
</style>